package com.example.basic.web.controller.role;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.role.Role;
import com.example.basic.web.service.role.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * <p>
 * 角色管理 前端控制器
 * </p>
 */
@Api(value = "角色管理相关操作", tags = {"角色管理"})
@RestController
@RequestMapping("/api/v1/byg/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @Log(title = "角色管理", description = "新增更新")
    @ApiOperation(value="新增更新",notes = "新增更新")
    @PostMapping("/addOrUpdate")
    public Result<Role> addOrUpdate(@ApiParam(name = "role", value = "模型", required = true) @RequestBody Role role, HttpServletRequest request) {
        return ResultGenerator.genSuccessResult(roleService.addOrUpdate(role));
    }

    @Log(title = "角色管理", description = "删除")
    @ApiOperation(value="删除",notes = "删除")
    @PostMapping("/remove")
    public Result<Boolean> remove(@ApiParam(value = "角色编码",name = "roleCode") @RequestParam String roleCode) {
        return ResultGenerator.genSuccessResult(roleService.remove(roleCode));
    }


    @Log(title = "角色管理", description = "角色列表")
    @ApiOperation(value="角色列表",notes = "角色列表")
    @PostMapping("/queryList")
    public Result<IPage<Role>> queryList(
            @ApiParam(value = "角色名称",name = "searchParam",required = false) @RequestParam(required = false) String searchParam,
            @ApiParam(value = "是否显示停用 0-否,1-是",name = "isShowStop",required = false) @RequestParam(defaultValue = "0") String isShowStop,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<Role> queryPage = new Page<>(page, size);
        return ResultGenerator.genSuccessResult(roleService.queryList(queryPage,searchParam,isShowStop));
    }
}